from django.conf import settings
from itsdangerous import TimedJSONWebSignatureSerializer as Serializer
#生成邮件链接
def encode_signature_mail_url(data):
    # serializer = Serializer(秘钥, 有效期秒)
    serializer = Serializer(settings.SECRET_KEY, 300)
    # serializer.dumps(数据), 返回bytes类型
    token=serializer.dumps(data)
    return token.decode()
#解密邮件链接
def decode_signature_mail_url(token):
    serializer = Serializer(settings.SECRET_KEY, 300)
    try:
        data = serializer.loads(token)
    except Exception as e:
        return None
    return data

